﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.EbookModel.Service.Interface;
using Domain.EbookModel.Core;
using Domain.Tools;
using BaseEpub;
using Domain.UserModel.Service.Interface;
using EntAppFrameWork;
using Domain.SystemModel.Service.Interface;
using Domain.SystemModel.Relation;
using Domain.SystemModel.Core;
using System.Collections.Generic;
using Domain.UserModel.Core;
using System.Collections;

namespace EpubImport
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            try
            {
                DomainTest.Remoting();
                string opfPath = @"E:\MyCode\NetCode\AngleSharpDemo\有机化学样本3\有机化学样本3\OEBPS\content.opf";
                EbookInfo ebookInfo = new NdPressOpf().GetEbookInfo(opfPath);

                Ebook eb = new Ebook();
                eb.Author = ebookInfo.Author;
                eb.Name=ebookInfo.Name;
                //eb.Create(68719481504, 68719481329, eb, 68719481330, ebookInfo.Name, ebookInfo.Isbn, ebookInfo.Author, ebookInfo.Cover.ToString());
                eb.AuthorDescription = string.Empty;
                eb.CreateTime = DateTime.Now;
                eb.CreateUser = EntAppFrameWork.EntAppFrameWorkContext.DomainModelService.ExtenedService<IUser>().GetUser(68719481330);
                eb.EbookCover = ebookInfo.Cover.ToString();
                eb.EBookDescription = string.Empty;
                eb.EbookType = EbookType.Undetermined;
                eb.ISBN = ebookInfo.Isbn;
                eb.IsGarbage = false;
                eb.IsValid = true;
                eb.LastUpdateTime = DateTime.Now;
                eb.Price = 0;
                eb.PublishTime = DateTime.Now;
                eb.StateType = StateType.Editing;

                //Ebook eb = EntAppFrameWork.EntAppFrameWorkContext.DomainModelService.ExtenedService<IEbook>().GetEbookById(4295828931);

                //EntAppFrameWorkContext.DomainModelService.Save<Ebook, Int64>(eb);

                ////往教材与课程资源表添加关系数据
               bool result= EntAppFrameWorkContext.DomainModelService.ExtenedService<ISubjectCourceRelation>()
                    .Create(68719481504, 68719481510, StudyResourceType.Ebook);

                //往教材与内容提供商表添加关系数据
                //bool result = EntAppFrameWorkContext.DomainModelService.ExtenedService<IContentProviderRelation>()
                //       .Create(68719481329, 68719481510, ResourceType.Ebook);

                Assert.IsNotNull(eb);
            }
            catch (Exception ex)
            {

            }

        }

        [TestMethod]
        public void TestMethod11()
        {
            try
            {
                DomainTest.Remoting();
                string opfPath = @"E:\MyCode\NetCode\AngleSharpDemo\有机化学样本3\有机化学样本3\OEBPS\content.opf";
                EbookInfo ebookInfo = new NdPressOpf().GetEbookInfo(opfPath);

                INcxBase ncx = new NdPressNcx();
                string ncxPath = @"E:\MyCode\NetCode\AngleSharpDemo\有机化学样本3\有机化学样本3\OEBPS\toc.ncx";
                IList<SectionBaseInfo> secList = ncx.GetSecList(ncxPath);

               
                IList<SectionBase> list = new List<SectionBase>();

                Dictionary<IList<SectionBaseInfo>, IList<SectionBase>> dic = new Dictionary<IList<SectionBaseInfo>, IList<SectionBase>>();
                IList<SectionBase> secLi=new List<SectionBase>();
                dic.Add(secList,secLi);
                //Dictionary<Page, PageContentInfo> pdic = new Dictionary<Page, PageContentInfo>();
                Dictionary<SectionBaseInfo, SectionBase> dicsec = new Dictionary<SectionBaseInfo, SectionBase>();
                Dictionary<SectionBase, SectionBaseInfo> dicsec2 = new Dictionary<SectionBase, SectionBaseInfo>();

                Ebook eb = EntAppFrameWorkContext.DomainModelService.ExtenedService<IEbook>().GetEbookById(68719481510);
                User u=EntAppFrameWorkContext.DomainModelService.ExtenedService<IUser>().GetUser(68719481330);

                foreach (var item in secList)
                {
                  
                    SectionBase sec = new SectionBase();
                     dicsec.Add(item,sec);
                     dicsec2.Add(sec, item);
                    sec.Ebook = eb;
                    sec.CreateUser = u;

                    PageContentInfo pp=new PageContentInfo();
                    pp.Content = item.PageContentInfo.Content;
                    pp.PageNum = item.PageContentInfo.PageNum;

                    Page p=new Page();
                    p.Content = pp.Content;
                    p.PageNumber = pp.PageNum;
                    p.Section = sec;
                    p.Ebook = sec.Ebook;
                    p.CreateUser = sec.CreateUser;
                    p.IsValid = true;
                    p.LastUpdateTime = DateTime.Now;
                    p.CreateTime = DateTime.Now;


                    //dic.Add(item,sec);
                    //pdic.Add(p, pp);
                    sec.Cover = string.Empty;
                    sec.CreateTime = DateTime.Now;

                    if (item.ParentId == 0)
                    {
                        sec.Parent = null;
                    }
                    else
                    {
                        //sec.Parent =secList. dicsec[item.ParentId].Parent;
                    }

                    if (item.ParentId == 0)
                    {
                        sec.FinalParent = sec;
                    }
                    else
                    {
                        sec.FinalParent = sec.Parent.FinalParent;
                    }
                    
                    //sec.Grade
                    sec.IndexNumber = string.Empty;
                    if(item.Grade==1){
                        sec.IsShowChapter = true;
                    }
                    else
                    {
                        sec.IsShowChapter = false;
                    }
                    sec.IsValid = true;
                    sec.LastUpdateTime = DateTime.Now;
                    sec.Name = item.Name;
                    sec.OrderBy = item.OrderBy;
                    sec.OriginalEbookNum = string.Empty;
                    
                    //sec.PositionPage
                    //sec.PrefixName
                    sec.Sort = item.Sort;
                    
                }

                Assert.IsNotNull(ebookInfo);
            }
            catch (Exception ex)
            {

            }

        }
    }
}
